#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "extmem.h"
#define BASE2 (200)
#define BASE3 (300)
#define BASE4 (400)
#define INDEX_R (350)
#define INDEX_S (450)
#define INDEX_NUM_R (7)
#define INDEX_NUM_S (7)
#define RESULT3 (500)
#define RESULT4 (600)
#define RESULT5 (700)
#define RESULT6 (800)
struct Tuple
{
    int first;
    int second;
};
struct MergeInfo
{
    unsigned char *blk; // 当前磁盘块数据首地址
    int valid;          // 有效位，或者剩余有效磁盘数
    int scan_pos;       // 当前扫描偏移量
    int cur_head;       // 当前第一个元组的第一个值
};
struct ConnectInfo
{
    struct Tuple tuple_R[16];
    int R_num;
    struct Tuple tuple_S[16];
    int S_num;
};
// get the pos-th turple (First, Second) of blk
void GetTuple(struct Tuple *tuple, int pos, unsigned char *blk);

int Compare(const char *a, const char *b);
void FindMin(struct MergeInfo info[], int num, int *cur_min, int *cur_pos);
void Merge_8(int start, int *IO);
void Merge_16_R(int start, int *IO);
void Merge_32_S(int start, int *IO);
void Index(int start, int num, int index_addr, int *IO);
int IsRepeat(int *a[], int num, int x);